package com.zt.business.service;

import com.zt.business.vo.ResponseData;
import com.zt.model.entity.User;
import com.zt.model.mapper.UserMapper;

import java.util.List;
import java.util.Objects;

public class UserService extends BaseSerivce<UserMapper> {
    public int insert(User pojo)
    {
        instance(UserMapper.class);
        return mapper.insert(pojo);
    }

    public int insertList(List< User> pojos){
        instance(UserMapper.class);
        return mapper.insertList(pojos);
    }

    public List<User> select(User pojo){
        instance(UserMapper.class);
        return mapper.select(pojo);
    }

    public int update(User pojo){
        instance(UserMapper.class);
        return mapper.update(pojo);
    }

    public ResponseData login(String logName, String logPwd, String code, Object sessionCode) throws Exception{
        //验证码为空
        if (Objects.isNull(sessionCode)){
            throw new Exception("验证码为空");
        }
        String sessionCd= (String) sessionCode;
        if (!code.equalsIgnoreCase(sessionCd)){
            return ResponseData.responseErrorData("验证码有误！");
        }
        instance(UserMapper.class);
        User user= mapper.login(logName,logPwd);
        if (Objects.isNull(user)){
            return ResponseData.responseErrorData("用户名或密码有误！");
        }
        user.setPwd(null);
        return ResponseData.responseSuccessData("登录成功",user);
    };
}
